<?php get_header(); 
$terms = get_term_by('slug', $term, $taxonomy);
?>
<div id="container">	
    
    <div class="wrapper">
    	<div class="grid24" style="margin-top:20px;">
        	<?php get_sidebar(); ?>
            <div class="grid18"><!-- content -->
            	<div class="crumbs">
                	<?php qt_custom_breadcrumbs(0, 1); ?>
                </div> 
            	<!-- crumbs -->         	
                
              <section class="grid18">
                	<h1><?php echo $terms->name; ?></h1>
                    <div class="white_frame">
					<?php 
					//echo $terms->term_id;
					//print_r($terms);
					//echo $taxonomy;
					/*
					$args = array(
						'post_type'		=> 'cruise',
						'post_status' 	=> 'publish',
						'tax_query' => array(
							'taxonomy' 	=> 'cruise_category',
							'field' 	=> 'slug',
							'terms' 	=> $terms->slug,
							//'operator' 	=> 'IN'
						 	//$terms->term_id,
						),
						'meta_query' => array(
							array(
								'key' 	=> '_mb_top',
								'value' => 1
							)
						),
						'orderby' 		=> 'date',
						'order'			=> 'DESC',
						'showposts'		=> -1
					);
					$cruises = new WP_Query($args);
					//print_r($cruises);
					while ( $cruises->have_posts() ) {
						$cruises->the_post();
						?><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><?php
					}
					///////////////////////////////////
					$args = array(
						'post_type'		=> 'cruise',
						'post_status' 	=> 'publish',
						'tax_query' => array(
							'taxonomy' 	=> 'cruise_category',
							'field' 	=> 'id',
							'terms' 	=> $terms->term_id,
							//'operator' 	=> 'IN'
						 	//$terms->term_id,
						),
						'orderby' 		=> 'date',
						'order'			=> 'DESC',
						'showposts'		=> -1
					);
					query_posts($args);
					while (have_posts()) : the_post();
						?><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><?php
						//$thuoctinh_arr = get_post_meta( $post->ID, '_mb_thuoctinh', true );
						//echo $thuoctinh_arr["tomtat"];
						
					endwhile;
					/////////////////////////////////////
					
					$mysql = $wpdb->get_results("SELECT p.ID, post_title, post_name
						FROM $wpdb->posts p 
						INNER JOIN $wpdb->postmeta pm ON(p.ID = pm.post_id)
						INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
						INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
						WHERE (pm.meta_key='_mb_top' AND pm.meta_value=1) AND
							tt.term_id=". $terms->term_id ." AND tt.taxonomy='{$taxonomy}' AND 
							post_type='cruise' AND post_status='publish' AND post_parent=0 ORDER BY post_date DESC;");
					
					*/
					$mysql = $wpdb->get_results("SELECT p.ID, post_title, post_name
						FROM $wpdb->posts p 
						INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
						INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
						WHERE tt.term_id=". $terms->term_id ." AND tt.taxonomy='{$taxonomy}' AND post_type='cruise' AND post_status='publish' AND post_parent=0 ORDER BY post_date DESC;");
					foreach ( $mysql as $post ) { 
						?>
                            <article class="recommend">
                                <figure class="featured-thumbnail">
                                     <a href="<?php the_permalink(); ?>">
                                            <?php 
                                                if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                                                  the_post_thumbnail('thumbnail');
                                                } 
                                             ?>
                                     </a>                                   
                                </figure>
                                <div class="grid12">
                                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                    <p>
                                    <?php 
                                        $thuoctinh_arr = get_post_meta( $post->ID, '_mb_attribute', true );
                                        echo $thuoctinh_arr["tomtat"];
                                        //echo GetWords($thuoctinh_arr["tomtat"], 350);
                                    ?>
                                    </p>                            
                                </div>                    	
                            </article>
						<?php
					}
					?>
                    </div><!-- end white_frame -->
                </section>
    
          </div><!-- content -->
            
        </div><!-- grid 24 -->
    </div><!-- wrapper -->
   
</div> <!-- container -->
<?php get_footer(); ?>